library(readxl)
library(lattice)
library(ggplot2)
setwd("_____")

hourly_betahat <- read_excel("hourly_betahat_clean.csv",col_names=FALSE)
twfecovmat <- read_excel("twfecovmat_clean.csv",col_names=FALSE)
#### Figure 2
levelplot(data.matrix(twfecovmat),col.regions=topo.colors(20))
beta<-diag(data.matrix(hourly_betahat))
sumtwfevar<-rowSums(data.matrix(twfecovmat))

#### Table 3A
weightLF<-sumtwfevar/sum(sumtwfevar)
twfevar<-diag(data.matrix(twfecovmat))
weightHF<-twfevar/sum(twfevar)
betaweight<-data.frame(rbind(beta,weightLF,weightHF))
write.csv(betaweight,"Table3A.csv")

#### Figure B1
levelplot(data.matrix(t(hourly_betahat)),col.regions=topo.colors(20))

#### Table 3B
sumbetagamma<-rowSums(t(data.matrix(hourly_betahat)))
betaweightLFexact<-data.frame(rbind(sumbetagamma,twfevar/sum(sumtwfevar)))
betahatLF<-sum(sumbetagamma*(twfevar/sum(sumtwfevar)))
write.csv(betaweightLFexact,"Table3B.csv")